package query

import (
	"ssdevice/common/dto"
	"strings"
)

type SysDevVariableQuery struct {
	dto.Pagination `search:"-"`
	dto.OrderBy    `search:"-"`
	dto.UserInfo
	Sn         string `form:"sn"  search:"type:exact;column:sn;table:sys_dev_variable"`
	Sns        string `form:"sns" search:"-"`
	Keys       string `form:"keys" search:"-"`
	KeyNot     string `form:"keyNot" search:"-"`
	DeptId     string `form:"deptId" search:"-"`
	DeptIdNot  string `form:"deptIdNot" search:"-"`
	DevName    string `form:"devName" search:"-"`
	DevSn      string `form:"devSn" search:"-"`
	ProductNot string `form:"productNot" search:"-"`
	Type       string `form:"type"  search:"type:exact;column:type;table:sys_dev_variable"`

	SnIn           []string `search:"type:in;column:sn;table:sys_dev_variable"`
	KeyIn          []string `search:"type:in;column:key;table:sys_dev_variable"`
	KeyNotIn       []string `search:"type:nin;column:key;table:sys_dev_variable"`
	SnKeyConcatIn  []string `search:"type:concatin;column:sn,key;table:sys_dev_variable"`
	SnKeyConcatNIn []string `search:"type:concatnin;column:sn,key;table:sys_dev_variable"`

	TagEq        string `form:"tag" search:"-"`
	AlarmStatus  *bool  `form:"alarmStatus"  search:"-"`
	OnlineStatus string `form:"onlineStatus"  search:"-"`
}

func (m *SysDevVariableQuery) GetNeedSearch() interface{} {
	if len(m.Sns) > 0 {
		m.SnIn = strings.Split(strings.ReplaceAll(m.Sns, " ", ""), ",")
	}
	if len(m.Keys) > 0 {
		m.KeyIn = strings.Split(strings.ReplaceAll(m.Keys, " ", ""), ",")
	}
	if len(m.KeyNot) > 0 {
		m.KeyNotIn = strings.Split(strings.ReplaceAll(m.KeyNot, " ", ""), ",")
	}
	return *m
}
